<template>
	<view class="equipment">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				设备信息
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop clearfix" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="left fl">
				{{device.charger_name}}
			</view>
			<view class="right fr clearfix" @click="topage('/subpackageA/goods/chargeredit?id='+device.id)">
				<image :src="baseUrl + '/wximage/bianji.png'" class="fl"></image>
				<view class="name fl">编辑</view>
			</view>
		</view>
		<view class="nr">
			<view class="list">
				<view class="liebiao clearfix">
					<view class="left fl">设备编号：</view>
					<view class="right fl">
						<view class="title">{{device.charger_number}}</view>
					</view>
				</view>
				<view class="liebiao clearfix">
					<view class="left fl">房间号：</view>
					<view class="right fl">
						<view class="title" v-if="device.roomno != null">{{device.roomno}}</view>
						<view class="title" v-else></view>
					</view>
				</view>
				<view class="liebiao clearfix">
					<view class="left fl">设备型号：</view>
					<view class="right fl">
						<view class="title">{{device.charger_typename}}</view>
					</view>
				</view>
				<view class="liebiao clearfix">
					<view class="left fl">wifi信息：</view>
					<view class="right fl">
						<view class="title">{{device.wifiname}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="mendian" v-if="device.type == 2">
			<view class="heads clearfix">
				<view class="left fl">
					<image :src="baseUrl + '/wximage/hktubiao.png'"></image>
					<view class="name">商品</view>
				</view>
				<view class="right fr" @click="topage('/subpackageA/goods/select?charger_id='+device.id)">
					<image :src="baseUrl + '/wximage/add.png'"></image>
					<view class="name">选择商品</view>
				</view>
			</view>
			<view class="shuju" v-if="list.length != 0">
				<view class="li clearfix" v-for="(item,index) in list" :key="index" @click="topage('/subpackageA/goods/edit?goodscharger_id='+item.id)">
					<image :src="item.sitepicture" class="fl"></image>
					<view class="cen fl">
						<text class="title">{{item.name}}</text>
						<text class="address">售价：￥{{item.danjia}}元</text>
						<text class="address">成本价：￥{{item.costprice}}元</text>
					</view>
				</view>
			</view>
			<view class="empty" v-else>
				<image :src="baseUrl + '/wximage/empty.png'"></image>
				<text>暂无数据</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				list: [],
				formData:{
					sn: '',
				},
				device:{},
				charger_id: '',
			}
		},
		onLoad(options) {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
			this.formData.sn = options.deviceid;
		},
		onShow() {
			this.deviceInfo();
		},
		methods: {
			//设备详情信息
			deviceInfo(){
				this.request({
					url: '/xcx/deviceinfo',
					data: this.formData,
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						this.device = res.data.data;
						
						this.getList();
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				})
			},
			//商品信息
			getList(){
				let charger_id = this.device.id;
				
				this.request({
					url: '/xcx/devicegoods',
					data: {
						charger_id: charger_id,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						this.list = res.data.data;
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				})
			},
			topage(url){
				uni.navigateTo({
					url
				})
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.equipment {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 10rpx 40rpx 0;
			box-sizing: border-box;

			.left {
				font-size: 32rpx;
				color: #333333;
				font-weight: 700;
			}
			
			.right {
				width: 116rpx;
				height: 36rpx;
				line-height: 36rpx;
				text-align: center;
				background: #FFFFFF;
				border-radius: 24rpx;
				margin-top: 6rpx;
			
				image {
					width: 36rpx;
					height: 36rpx;
					margin-left: 10rpx;
					margin-right: 6rpx;
				}
			
				.name {
					font-size: 24rpx;
					color: #333333;
				}
			}
		}
		
		.nr{
			width: 90%;
			margin: 0 auto;
			z-index: 70;
			margin-top: -220rpx;
			box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;
			position: relative;
			
			.list{
				width: 100%;
				background: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 40rpx 40rpx 10rpx;
				
				.liebiao{
					margin-bottom: 30rpx;
					
					.left{
						font-size: 24rpx;
						color: #333333;
						width: 30%;
					}
					
					.right{
						
						.title{
							font-size: 24rpx;
							color: #333333;
							
							text{
								font-size: 24rpx;
								color: #333333;
							}
						}
						
						.name{
							font-size: 24rpx;
							color: #5C88FA;
						}
					}
				}
			}
			
			.tanbao{
				position: absolute;
				right: 20rpx;
				bottom: 90rpx;
				
				.name{
					font-size: 24rpx;
					color: #333333;
					margin-right: 8rpx;
				}
				
				image{
					width: 32rpx;
					height: 32rpx;
					margin-top: -4rpx;
				}
			}
		}
		
		.mendian{
			width: 90%;
			margin: 0 auto;
			z-index: 70;
			margin-top: 30rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;
			
			.heads{
				width: 100%;
				padding: 24rpx 20rpx 0;
				box-sizing: border-box;
				
				.left{
					
					image{
						float: left;
						width: 40rpx;
						height: 40rpx;
						margin-top: -6rpx;
					}
					
					.name{
						font-size: 28rpx;
						color: #333333;
						float: left;
					}
				}
				
				.right{
					
					image{
						float: left;
						width: 34rpx;
						height: 34rpx;
						margin-top: -6rpx;
					}
					
					.name{
						font-size: 24rpx;
						color: #368BF8;
						float: left;
					}
				}
			}
			
			.shuju{
				width: 100%;
				padding: 30rpx 26rpx;
				box-sizing: border-box;
				
				.li{
					width: 100%;
					position: relative;
					padding-bottom: 20rpx;
					margin-bottom: 20rpx;
					border-bottom: 1rpx solid #F1F1F1;
					
					image{
						width: 120rpx;
						height: 120rpx;
					}
					
					.cen{
						width: 480rpx;
						margin-left: 20rpx;
						
						text{
							display: block;
						}
						
						.title{
							font-size: 28rpx;
							color: #333333;
							font-weight: 700;
							margin-bottom: 10rpx;
						}
						
						.address{
							font-size: 24rpx;
							color: #666666;
							margin-bottom: 6rpx;
						}
						
						.time{
							font-size: 24rpx;
							color: #999999;
						}
					}
					
					.bili{
						position: absolute;
						right: 0;
						bottom: 40rpx;
						width: 120rpx;
						height: 32rpx;
						line-height: 32rpx;
						text-align: center;
						background: #3B91F8;
						color: #FFFFFF;
						border-radius: 16rpx;
						font-size: 22rpx;
					}
				}
				
				.li:last-child{
					border: none;
					margin-bottom: 0;
					padding-bottom: 0;
				}
			}
		}
		
		.empty{
			width: 100%;
			margin: 20rpx auto 0;
			text-align: center;
			padding-bottom: 20rpx;
			
			image{
				width: 390rpx;
				height: 340rpx;
			}
			
			text{
				display: block;
				margin-top: 30rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}
	}
</style>